package com.lagou.common.dao;

import com.lagou.common.pojo.FlashSale;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface FlashSaleDao extends JpaRepository<FlashSale, Long> {
    List<FlashSale> findFlashSaleByName(String name);

    /**
     * 库存减1
     * @param id
     */
    @Modifying
    @Transactional
    @Query("update FlashSale set stock = stock - 1 where id = ?1")
    void decreaseOneStock(Long id);
}
